/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.soa.service.busi.wx;

import com.lianzt.commondata.AbstractCommonData;
import com.lianzt.commondata.DataConvertFactory;
import com.soa.exception.GlobalException;
import com.soa.service.BaseService;
import com.soa.util.SystemUtil;
import com.soa.util.tccgl.WeixinUtil;
import javax.annotation.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

/**
 *  人员借支
 *  P90012
 * @author chang
 */
@Service
public class RyjzService extends BaseService{
    @Resource
    private WeixinUtil wx;
    private final Logger log = LoggerFactory.getLogger(RyjzService.class);
    @Override
    public String[] keys() {
        return null;
    }

    @Override
    public void execute(AbstractCommonData in, AbstractCommonData inhead, AbstractCommonData out, AbstractCommonData outhead) {
        String id = SystemUtil.getSerialNum();
        String jzr = in.getStringValue("jzr");
        String jzje = in.getStringValue("jzje");
        String lxfs = in.getStringValue("lxfs");
        String jzrq = in.getStringValue("jzrq");
        String jzsm = in.getStringValue("jzsm")==null?"无":in.getStringValue("jzsm");
        
        in.putStringValue("id", id);
        try {
            update("insert_ryjz", in);
            //系统给管理用户发一条人员借支消息
            //获取通知管理人员的openid
            String tz_openid = SystemUtil.getSysConfig("gly_openid");
            String context="【系统提醒】\n"
                    + "有新的人员借支信息！\n"
                    + "借支人："+jzr+"\n"
                    + "借支金额："+jzje+"\n"
                    + "联系方式："+lxfs+"\n"
                    + "借支日期："+jzrq+"\n"
                    + "借支说明："+jzsm;
            log.debug("---------------context:"+context);
            try {
                    String code = wx.sendMessage(tz_openid, "", "", "text", 13, context);
                    AbstractCommonData ab= DataConvertFactory.getInstanceByJson(code);
                    log.debug("调用企业号发送信息返回:{}"+ab);
                    if("ok".equals(ab.getStringValue("errmsg"))){
                        log.debug("----------------------企业号发送消息成功!");
                    }
                } catch (Exception e) {
                    log.error("企业号发送消息失败!", e);
                }
        } catch (Exception e) {
            //保存借支信息异常
            throw new GlobalException(9001201,e);
        }
        
        
    }
    
}
